package com.qf.common;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class StreamUtils {
    public static String readStreamData(InputStream inputStream){


        //BufferedInputStream bufferStream =new BufferedInputStream(inputStream);
        //byte [] buffer = new byte[1024];
        //int length = 0;
        //StringBuilder builder = new StringBuilder();
        //try {
        //    while((length = bufferStream.read(buffer))!=-1){
        //        builder.append(new String(buffer,0,length));
        //    }
        //} catch (IOException e) {
        //    throw new RuntimeException(e);
        //}
        //return builder.toString();

        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
        //BufferedInputStream bufferStream =new BufferedInputStream(inputStream,StandardCharsets.UTF_8);
        byte [] buffer = new byte[1024];
        String  length ;
        StringBuilder builder = new StringBuilder();
        try {
            while((length = reader.readLine()) != null){
                builder.append(length);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return builder.toString();
    }
}
